package com.itheima.jdk8_DateDemo;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class Test5 {
    public static void main(String[] args) {
        //获取LocalDateTime对象
        LocalDateTime now = LocalDateTime.now();
        //使用对象调用format方法格式化成字符串
         String result = now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));

        System.out.println(result);
        //   public static LocalDateTime parse(准备解析的字符串,解析格式),把一个日期字符串解析成一个LocalDateTime对象
        LocalDateTime parse = LocalDateTime.parse(result, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));


        System.out.println(parse);
    }
}
